local lizhan = fk.CreateSkill {

  name = "joysp__lizhan",

  tags = {  },

}



lizhan:addEffect(fk.EventPhaseStart, {
  name = "joysp__lizhan",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lizhan.name) and player.phase == Player.Finish
    and table.find(player.room.alive_players, function(p) return p:isWounded() end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p) return p:isWounded() end)
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, #targets, "#lizhan-choose", lizhan.name, true)
    if #tos > 0 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self)
    room:sortPlayersByAction(tos)
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        p:drawCards(1, lizhan.name)
      end
    end
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      if p:getHandcardNum() == p.hp and not player.dead then
        player:drawCards(1,lizhan.name)
      end
    end
  end,
})

return lizhan